#coding:utf-8
import httplib,urllib,os,threading,re


def httpRequest(method,url,para={}):
    print method
    #try:
    _urld = httplib.urlsplit(url)
    print _urld.netloc
    conn = httplib.HTTPConnection(_urld.netloc,80,True,5)
    conn.connect()
    para = urllib.urlencode(para)
    if method == 'get':
        conn.putrequest("GET",url,None)
        conn.putheader("Content-Length",'0')
    elif method == 'post':
        conn.putrequest("POST",url)
        conn.putheader("Content-Length",str(len(para)))
    conn.putheader("Connection","close")
    conn.endheaders()
    data = "qq=296770220&pwd=315941518&bid_code=3GQQ&toQQchat=true&login_url=http%3A%2F%2Fpt.3g.qq.com%2Fs%3Faid%3DnLoginnew%26q_from%3D3GQQ&q_from=&modifySKey=0&loginType=1&aid=nLoginHandle"
    if len(para):
        print para
        conn.send(data)

    response = conn.getresponse()
    httpbody = response.read()
    response.close()
    conn.close()
    #except:
    #    httpbody = '22'
    return httpbody

def login():
    #self.qq = raw_input('QQ:')
    #self.pwd = raw_input('password:')
    qq = '296770220'
    pwd = '315941518'
    
    loginresponse = httpRequest('post','http://pt.3g.qq.com/psw3gqqLogin?r=480188441&vdata=073B2F128DF6AA1489AB58273699AAB8',{'qq':qq,'pwd':pwd,'toQQchat':'true','q_from':'','modifySKey':'0','loginType':'1','aid':'nLoginHandle','login_url':'http://pt.3g.qq.com/s?aid=nLoginnew&q_from=3GQQ','bid_code':'3GQQ',})
    print loginresponse


if __name__ == "__main__":
    
    login()
